home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Fitts / ExpController.m < prev    next >
Encoding:
Text File  |  1992-07-28  |  4.7 KB  |  196 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import <sys/time.h>
  5. #import <appkit/Button.h>
  6. #import <libc.h>
  7. #import "ExpController.h"
  8.  
  9.  
  10. @implementation ExpController
  11.  
  12.  
  13. - startSquareHit
  14. {
  15.     struct timeval tp;
  16.     struct timezone tzp;
  17.     
  18.     gettimeofday(&tp, &tzp);
  19.     
  20.     startTime = (tp.tv_sec & 0xffff) * 1000000 + tp.tv_usec;
  21.  
  22.     fprintf(stderr, "startSec:%d, startuSec:%d, startTime:%d\n", tp.tv_sec, tp.tv_usec, startTime);
  23.     
  24.     hitItem = random() % menuParms.num_items;
  25.     
  26.     [expMenuView setHitItem:hitItem];
  27.     
  28.     return self;
  29. }
  30.  
  31. - menuItemHit:(int) item_num
  32. {
  33.     struct timeval tp;
  34.     struct timezone tzp;
  35.     long total;
  36.     unsigned long end_time;
  37.  
  38.     gettimeofday(&tp, &tzp);    
  39.     
  40.     end_time = (tp.tv_sec & 0xffff) * 1000000 + tp.tv_usec;
  41.    
  42.     total = end_time - startTime;
  43.  
  44.     fprintf(stderr, "endSec:%d, enduSec:%d, end_time:%d, total:%d\n", tp.tv_sec, tp.tv_usec, end_time, total);
  45.  
  46.     fprintf(outputFile, "\t%.3f\t", ((float) total) / 1000000.0);
  47.  
  48.     fprintf(outputFile, "%s", hitItem == item_num ? "hit" : "miss");
  49.     
  50.     if ( menuParms.menu_type == VERTICAL )
  51.     {
  52.         float item_distance;
  53.     
  54.     item_distance = abs(menuParms.num_items/2 - item_num) *
  55.                      (menuParms.option2+menuParms.option3);        
  56.         fprintf(outputFile, "\t\t%.2f\n", item_distance);        
  57.     fprintf(stderr, "\t%.2f\n", item_distance);
  58.     }
  59.     else if ( menuParms.menu_type == CIRCLE_PIE )
  60.         fprintf(outputFile, "\t\t%.2f\n", menuParms.option2);
  61.     else
  62.         fprintf(outputFile, "\t\t%.2f\n", menuParms.option3);
  63.  
  64.     if ( trialsToGo > 1 )
  65.     {
  66.         trialsToGo--;
  67.         [expMenuView setStartState];
  68.     }
  69.     else
  70.     {
  71.         fprintf(stderr, "done experiment\n");
  72.     fprintf(outputFile, "done experiment\n\n");
  73.     fclose(outputFile);
  74.     
  75.     [statusText setStringValue:"DONE EXPERIMENT -- hit Ready to continue.\n"];
  76.     [readyButton setEnabled:1];
  77.     }
  78.  
  79.     return self;
  80. }
  81.  
  82. - menuItemMissed
  83. {
  84.     struct timeval tp;
  85.     struct timezone tzp;
  86.     long total;
  87.     unsigned long end_time;
  88.     
  89.     gettimeofday(&tp, &tzp);    
  90.  
  91.     end_time = (tp.tv_sec & 0xff) * 1000000 + tp.tv_usec;
  92.    
  93.     total = end_time - startTime;
  94.     
  95.     fprintf(stderr, "endSec:%d, enduSec:%d, end_time:%d, total:%d\n", tp.tv_sec, tp.tv_usec, end_time, total);
  96.  
  97.     fprintf(outputFile, "%.3f\t\tmiss\n", ((float) total) / 1000000.0);
  98.     
  99.     if ( trialsToGo > 1 )
  100.     {
  101.         trialsToGo--;
  102.         [expMenuView setStartState];
  103.     }
  104.     else
  105.     {
  106.         fprintf(stderr, "done experiment\n");
  107.     fprintf(outputFile, "done experiment.\n");
  108.     fclose(outputFile);
  109.     }
  110.  
  111.     return self;
  112. }
  113.  
  114.  
  115. - readyButtonHit:sender
  116. {
  117.     fprintf(stderr, "Ready button hit.\n");
  118.  
  119.     [sender setEnabled:0];
  120.     
  121.     if ( trialsToGo == 0 )
  122.     {
  123.         /* close this window and open control and results window */
  124.     }
  125.     else
  126.         [expMenuView setStartState];
  127.     
  128.     return self;
  129. }
  130.  
  131. - computeArea:(float *) area
  132. {
  133.     switch ( menuParms.menu_type )
  134.     {
  135.         case VERTICAL:
  136.     case CIRCLE_RECTANGLE:
  137.         *area = menuParms.option1 * menuParms.option2;
  138.         break;
  139.         
  140.     case CIRCLE_PIE:
  141.         *area = ((3.14159*(menuParms.option2+menuParms.option3) * 
  142.                               (menuParms.option2+menuParms.option3)) -
  143.                      (3.14159*menuParms.option2*menuParms.option2)) /
  144.                                        (360.0/menuParms.option1);
  145.         break;
  146.     }
  147.     
  148.     return self;
  149. }
  150.  
  151.  
  152. - performExperiment:(MVParms *) menu_parms :(int) num_trials :(char *) exp_id
  153. {
  154.     float item_area;
  155.     
  156.     outputFile = fopen(exp_id, "a+");
  157.     
  158.     srandom((int) time(NULL) );
  159.     
  160.     menuParms = *menu_parms;
  161.     trialsToGo = num_trials;
  162.     
  163.     
  164.     fprintf(outputFile, "***\nExperiment id:%s\n", exp_id);
  165.     fprintf(outputFile, "# menu items:%d, # of trials:%d\n",
  166.                               menu_parms->num_items, num_trials);
  167.  
  168.     if ( menu_parms->menu_type == VERTICAL )
  169.     {
  170.         fprintf(outputFile, "VERTICAL menu:\n\twidth:%.2f, height:%.2f, distance:%.2f\n",
  171.             menu_parms->option1, menu_parms->option2, menu_parms->option3);
  172.     }
  173.     else if ( menu_parms->menu_type == CIRCLE_PIE )
  174.     {
  175.         fprintf(outputFile, "CIRCULAR PIE menu:\n\tangle covered:%.2f, radius covered:%.2f, menu radius:%.2f\n", menu_parms->option1, menu_parms->option2,
  176.             menu_parms->option3);
  177.     }
  178.     else
  179.         fprintf(outputFile, "CIRCULAR RECT menu:\n\twidth:%.2f, height:%.2f, radius:%.2f\n", menu_parms->option1, menu_parms->option2, menu_parms->option3);
  180.  
  181.     [self computeArea:&item_area];    
  182.     fprintf(outputFile, "\tItem area: %.2f\n", item_area);
  183.     
  184.     fprintf(outputFile, "\nSelection Time\tHit/Miss\tDistance\n");
  185.     fprintf(outputFile, "--------------\t--------\t--------\n");
  186.         
  187.     [expMenuView setMenuParms:&menuParms];
  188.  
  189.     [readyButton setEnabled:1];
  190.         
  191.     return self;
  192. }
  193.  
  194.  
  195. @end
  196.